package algorithm.CattleAndSheepEatGrass;

public class EatGrass {

    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
            System.out.println("i = " + i + " value : " + EatGrass.win(i));
        }
    }

    public static String win(int n){
        if(n < 5)
            return n == 0 || n == 2 ? "后手" : "先手";
        int base = 1;
        while(base <= n){
            if( win(n - base).equals("后手"))
                return "先手";
            if(base > n / 4)
                break;
            base =  base * 4;
        }
        return "后手";
    }

}
